/****************************************************************************
*  Arthea Server by R. Jennings (2007-2008)   http://arthea.googlecode.com/ *
*  By using this code you comply with the Artistic and GPLv2 Licenses.      *
****************************************************************************/


using System;
using System.IO;

namespace Arthea.Globals
{
    /// <summary>
    /// Holds references to directories and files
    /// </summary>
    public struct Paths
    {
        private static readonly string rootDir = ".." + Path.DirectorySeparatorChar;
        private static readonly string varDir = rootDir + "var" + Path.DirectorySeparatorChar;
        private static readonly string etcDir = rootDir + "etc" + Path.DirectorySeparatorChar;
        private static readonly string libDir = rootDir + "lib" + Path.DirectorySeparatorChar;
        private static readonly string logDir = varDir + "log" + Path.DirectorySeparatorChar;
        private static readonly string areaDir = libDir + "area" + Path.DirectorySeparatorChar;
        private static readonly string clanDir = libDir + "clan" + Path.DirectorySeparatorChar;
        private static readonly string continentDir = libDir + "continent" + Path.DirectorySeparatorChar;
        private static readonly string noteDir = libDir + "notes" + Path.DirectorySeparatorChar;
        private static readonly string greetingFile = etcDir + "greeting.txt";
        private static readonly string helpFile = libDir + "help";
        private static readonly string motdFile = etcDir + "motd.txt";
        private static readonly string playerDir = libDir + "player" + Path.DirectorySeparatorChar;
        private static readonly string serverConfigFile = etcDir + "config";
        private static readonly string socialFile = libDir + "socials";


        /// <summary>
        /// Directory for players
        /// </summary>
        /// <value>the player path</value>
        public static string PlayerDir
        {
            get { return playerDir; }
        }

        /// <summary>
        /// Directory for log files
        /// </summary>
        /// <value>the log directory</value>
        public static string LogDir
        {
            get { return logDir; }
        }

        /// <summary>
        /// Directory for areas and continents
        /// </summary>
        /// <value>the lib directory path</value>
        public static string LibDir
        {
            get { return libDir; }
        }

        /// <summary>
        /// Directory for miscellaneous files
        /// </summary>
        /// <value>the etc dir</value>
        public static string EtcDir
        {
            get { return etcDir; }
        }

        /// <summary>
        /// Directory for saving areas
        /// </summary>
        /// <value>the area dir</value>
        public static string AreaDir
        {
            get { return areaDir; }
        }

        /// <summary>
        /// Directory for saving continents
        /// </summary>
        /// <value>the continent directory</value>
        public static string ContinentDir
        {
            get { return continentDir; }
        }

        /// <summary>
        /// Directory for saving clan members
        /// </summary>
        /// <value>the clan directory</value>
        public static string ClanDir
        {
            get { return clanDir; }
        }

        /// <summary>
        /// File to display greeting to a connection
        /// </summary>
        /// <value>the greeting file</value>
        public static string GreetingFile
        {
            get { return greetingFile; }
        }

        /// <summary>
        /// Gets the MOTD file.
        /// </summary>
        /// <value>The MOTD file.</value>
        public static string MOTDFile
        {
            get { return motdFile; }
        }

        /// <summary>
        /// File for saving helps
        /// </summary>
        /// <value>the help file path</value>
        public static string HelpFile
        {
            get { return helpFile; }
        }

        /// <summary>
        /// Gets the note dir.
        /// </summary>
        /// <value>The note dir.</value>
        public static string NoteDir
        {
            get { return noteDir; }
        }

        /// <summary>
        /// Gets the server config file.
        /// </summary>
        /// <value>The server config file.</value>
        public static string ServerConfigFile
        {
            get { return serverConfigFile; }
        }

        /// <summary>
        /// File for saving socials
        /// </summary>
        /// <value>the social file path</value>
        public static string SocialFile
        {
            get { return socialFile; }
        }


        /// <summary>
        /// Initializes the <see cref="Paths"/> class.
        /// </summary>
        static Paths()
        {
            try
            {
                if (!Directory.Exists(PlayerDir))
                    Directory.CreateDirectory(PlayerDir);

                if (!Directory.Exists(LogDir))
                    Directory.CreateDirectory(LogDir);

                if (!Directory.Exists(LibDir))
                    Directory.CreateDirectory(LibDir);

                if (!Directory.Exists(EtcDir))
                    Directory.CreateDirectory(EtcDir);

                if (!Directory.Exists(AreaDir))
                    Directory.CreateDirectory(AreaDir);

                if (!Directory.Exists(ContinentDir))
                    Directory.CreateDirectory(ContinentDir);

                if (!Directory.Exists(ClanDir))
                    Directory.CreateDirectory(ClanDir);

                if (!Directory.Exists(NoteDir))
                    Directory.CreateDirectory(NoteDir);
            }
            catch (Exception ex)
            {
                Log.Fatal("Initialize directories: {0}", ex.Message);
                Environment.Exit(1);
            }
        }
    }
}